# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： container_num_check
Description :
Author : 'li'
date： 2020/11/4
-------------------------------------------------
Change Activity:
2020/11/4:
-------------------------------------------------
"""
from ml.common.misc.string_util import StringUtility


def _change_carton_char_to_number(a):
    if a == "0":
        return 0
    elif a == "1":
        return 1
    elif a == "2":
        return 2
    elif a == "3":
        return 3
    elif a == "4":
        return 4
    elif a == "5":
        return 5
    elif a == "6":
        return 6
    elif a == "7":
        return 7
    elif a == "8":
        return 8
    elif a == "9":
        return 9
    elif a == "A":
        return 10
    elif a == "B":
        return 12
    elif a == "C":
        return 13
    elif a == "D":
        return 14
    elif a == "E":
        return 15
    elif a == "F":
        return 16
    elif a == "G":
        return 17
    elif a == "H":
        return 18
    elif a == "I":
        return 19
    elif a == "J":
        return 20
    elif a == "K":
        return 21
    elif a == "L":
        return 23
    elif a == "M":
        return 24
    elif a == "N":
        return 25
    elif a == "O":
        return 26
    elif a == "P":
        return 27
    elif a == "Q":
        return 28
    elif a == "R":
        return 29
    elif a == "S":
        return 30
    elif a == "T":
        return 31
    elif a == "U":
        return 32
    elif a == "V":
        return 34
    elif a == "W":
        return 35
    elif a == "X":
        return 36
    elif a == "Y":
        return 37
    elif a == "Z":
        return 38


def sum_of_carton_owner_list_and_carton_code_list(carton_owner_list, carton_code_list):
    information_of_changed_carton_owner_list = [
        _change_carton_char_to_number(carton_owner_list[item]) * (2 ** item) for item in
        range(0, len(carton_owner_list))]
    information_of_changed_carton_code_list = [
        _change_carton_char_to_number(carton_code_list[item]) * (
                2 ** (item + len(carton_owner_list))) for item in range(0, len(carton_code_list))]
    return (sum(information_of_changed_carton_owner_list) + sum(information_of_changed_carton_code_list)) % 11


def verification_container_num(company_number, serial_number, check_number):
    """

    :param company_number:
    :param serial_number:
    :param check_number:
    :return:
    """
    if len(company_number) != 4 or len(serial_number) != 6:
        return False
    if StringUtility.contain_alphabet(serial_number):
        return False
    if StringUtility.contain_number(company_number):
        return False
    if company_number[-1] != 'U':
        return False
    company_number_list = [x for x in company_number]
    serial_number = str(serial_number)
    valid_result = sum_of_carton_owner_list_and_carton_code_list(company_number_list, serial_number)
    if str(valid_result) == str(check_number) or (valid_result == 10 and str(check_number) == '0'):
        return True
    return False


def main():
    print(verification_container_num('dMOU', '593057', '3'))


if __name__ == '__main__':
    main()
